import java.util.Scanner;
//可见性
class  Counter{
    public volatile int flag=0;
}
public class ThreadDemo2 {
    public static int num = 0;
    public static void main(String[] args) {
        Counter counter=new Counter();
        Thread t = new Thread(() -> {
           while(counter.flag==0){
               System.out.println("开始循环");
           }
            System.out.println("循环结束");
        });
        Thread t2 = new Thread(() -> {
            Scanner scan=new Scanner(System.in);
            System.out.println("请输入一个数字来修改flag值");
            counter.flag=scan.nextInt();
        });
        t.start();
        t2.start();
    }
}
